Skip to content

Conversation

@jamesstout
Copy link

Re #37, I found a file that triggered the error, it was a ._* macOS resource fork.

My proposed fix is to check the encoding:

unless file_contents.valid_encoding?
    puts "Invalid encoding for #{filename_without_extension}" if options[:verbose]
    file_contents = fix_encoding(file_contents)
end

And if invalid, fix it:

def fix_encoding(file_contents)
    file_contents.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
end

I added my dodgy resource file to the fixtures, it broke the tests [without the new code]. I also added some invalid bytes to unused_class.h to check existing tests pass.

All tests pass. I built the gem and ran against my project with the resource fork, and it worked fine.

Turns out it was am AppleDouble encoded Macintosh file
Added an invalid byte to a test header file, tests with unused_class would fail if fix_encoding is not called.
Signed-off-by: James Stout <stoutyhk@gmail.com>
@dangerpr-bot
Copy link

2 Warnings
⚠️ [DEPRECATION] check is deprecated. Please use check! instead.
⚠️ Unless you’re refactoring existing code or improving documentation, please update CHANGELOG.md.

Here's an example of a CHANGELOG.md entry:

* [#39](https://github.com/dblock/fui/pull/39): Handle invalid byte sequences - [@jamesstout](https://github.com/jamesstout).

Generated by 🚫 Danger

@dblock
Copy link
Owner

dblock commented Aug 9, 2021

I don't think this is right. Files can have a different encoding and we should support that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants